package com.baymax.study.base.domain.listener;

import com.baymax.study.base.domain.entities.BaseEntity;

import javax.persistence.PostPersist;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import java.util.Date;

/**
 * BaseEntityListener
 *
 * @author Baymax
 * @since 2024-07-22
 */
public class BaseEntityListener {
    @PrePersist
    public void prePersist(BaseEntity entity) {
        entity.setCreateAccount("System");
        entity.setCreateDate(new Date());
    }

    @PreUpdate
    public void preUpdate(BaseEntity entity) {
        entity.setLastUpdateDate(new Date());
        entity.setLastUpdateAccount("System");
    }

    @PostPersist
    public void postPersist(BaseEntity entity) {

    }
}
